package cn.portx.view;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.bdf3.dorado.jpa.JpaUtil;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

import cn.portx.entity.Car;
import cn.portx.entity.Carrier;
import cn.portx.entity.Customer;
import cn.portx.entity.Fleet;
import cn.portx.entity.Memorandum;
import cn.portx.entity.Order;
import cn.portx.entity.Port;
import cn.portx.entity.ShippingCompany;
import cn.portx.entity.Vessel;
import cn.portx.entity.Wharf;

@Component
public class OrdersPR {

	@DataProvider
	@Transactional(readOnly = true)
	public void loadOrders(final Page<Order> page, Criteria criteria) {
		JpaUtil.linq(Order.class).collect(Customer.class, "customerId").collect(Fleet.class, "fleetId",
				"destFleetId")/* .collect(Car.class, "carId", "destCarId") */
				.collect(ShippingCompany.class, "shippingCompanyId").collect(Vessel.class, "vesselId").collect(Wharf.class, "wharfId")
				.collect(Port.class, "startPortId", "endPortId").collect(Carrier.class, "xsId").isNull("targetId").where(criteria).desc("orderNo").paging(page);
	}

	@DataProvider
	@Transactional(readOnly = true)
	public List<Memorandum> loadCurentBw(String orderId) {
		List<Memorandum> values = JpaUtil.linq(Memorandum.class).equal("orderId", orderId).list();
		return values;
	}
}
